package com.qf.service.impl;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainService;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Zwnan
 */
@Service("router")
public class RouterFilterServiceImpl implements FilterChainService {

    @Autowired
    private AmqpAdmin amqpAdmin;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public boolean stratrgy(StandardSubmit submit) {
        //获取运营商ID
        Integer operatorId = submit.getOperatorId();
        String queue = RabbitMQConstants.TOPIC_SMS_GATEWAY+operatorId;
        amqpAdmin.declareQueue(QueueBuilder.durable(queue).build());

        rabbitTemplate.convertAndSend(queue,submit);
        return true;
    }
}
